home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8986 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
  4. Subject: Re: GOTO controversy
  5. Date: 7 Mar 1996 21:00:08 GMT
  6. Organization: Prose Software
  7. Message-ID: <4hnioo$jbb@newshost.cyberramp.net>
  8. References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com>
  9. NNTP-Posting-Host: ramp2-13.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <4hlg11$dd7@news1.mnsinc.com>, huang@mnsinc.com says...
  13. >
  14. >John Noland (sinan@cyberramp.net) wrote:
  15. >
  16. >[snip]
  17. >:  DON'T use a goto unless it's the only solution to the problem.
  18. >:  You have many alternatives to a goto in your above code. 
  19. >
  20. >Wrong.  'goto' will never be the only solution.  When the 'goto'
  21. >solution is more elegant than the other choices (which is entirely
  22. >possible), use 'goto'.
  23. >
  24.  
  25. These are guidelines, not hard and fast rules. But, you're right, if this
  26. were true, then the situation I presented of breaking out of a nested loop
  27. would break this since there is an alternative. I probably should have
  28. worded that differently. Your response is better.
  29.  
  30. >:  A subroutine should have at most one label.
  31. >
  32. >Arbitrary number.  Does a subroutine with exactly *two* labels
  33. >automatically and magically become unreadable?
  34. >
  35. >:  All goto's should be above that label in the code.
  36. >
  37. >Above?  You mean all 'goto's should be forward jumps?  Why?
  38. >
  39.  
  40. The reason for these two is to develop a mindset. If I stray from these, I
  41. want the thought "Am I f***ing up here!" in my head. Using goto's
  42. can lead to a lazy attitude, which can lead to abuse. I currently maintain
  43. a huge set of COBOL code that is littered with goto's in every direction.
  44. Believe me, it's a bitch to make changes to this code and when I jump into
  45. it, it becomes real easy to say f*** it and do the same thing myself. If I
  46. let this attitude creep into my C programming I'd be a dead man. I
  47. advocate the judicious use of goto's. If I had to list one hard and fast
  48. rule it would be, keep the goto's and their labels in the same block of 
  49. execution. Have a little mercy on yourself and/or the person following you
  50. in the future. 
  51.  
  52. >That's the point against using 'goto's.  Realize however that a
  53. >good engineer is usually smarter than blind guidelines.  The
  54. >rules you raised have obvious drawbacks.  Personally, the rule
  55. >I impose upon myself is: "If you use a 'goto', you better have
  56. >a damn good reason for it and be prepared to explain why all
  57. >other constructs make the program uglier."
  58.  
  59. Well said! 
  60.  
  61. -John
  62.  
  63.